Ext.Loader.setPath('Ext.ux', CDR.Constant.CONTEXT_PATH + '/resources/extjs/examples/ux');
Ext.require([
     'Ext.ux.form.MultiSelect',
     'Ext.ux.form.ItemSelector',
 ]);
Ext.tip.QuickTipManager.init();

Ext.override(Ext.grid.Scroller, {
  afterRender: function() {
    var me = this;
    me.callParent();
    me.mon(me.scrollEl, 'scroll', me.onElScroll, me);
    Ext.cache[me.el.id].skipGarbageCollection = true;
    // add another scroll event listener to check, if main listeners is active
    Ext.EventManager.addListener(me.scrollEl, 'scroll', me.onElScrollCheck, me);
    // ensure this listener doesn't get removed
    Ext.cache[me.scrollEl.id].skipGarbageCollection = true;
  },

  // flag to check, if main listeners is active
  wasScrolled: false,

  // synchronize the scroller with the bound gridviews
  onElScroll: function(event, target) {
    this.wasScrolled = true; // change flag -> show that listener is alive
    this.fireEvent('bodyscroll', event, target);
  },

  // executes just after main scroll event listener and check flag state
  onElScrollCheck: function(event, target, options) {
    var me = this;

    if (!me.wasScrolled) {
      // Achtung! Event listener was disappeared, so we'll add it again
      me.mon(me.scrollEl, 'scroll', me.onElScroll, me);
    }
    me.wasScrolled = false; // change flag to initial value
  }

});
//create cutom vtype

Ext.define('CDR.Main', {
	extend:'Ext.Viewport',
	layout:'border',
	initComponent: function() {
		var me = this;
		me.callParent();
		//create our components
		me.root = Ext.create('widget.panel',{
			region: 'center',
			layout:'border',
			tbar : [{
				text: CDR.I18N['global.title'],
				iconCls: 'win-icon'
			},'->'
			,{
				text: CDR.Constant.User.name,
				iconCls: 'icon-pbx',
				menu: {
					width: '100',
					xtype: 'menu',
					items: {
						text:'Logout',
						iconCls:'icon-logout',
						handler: function(){
							document.location.href = 'j_spring_security_logout';
						}
					}
				}
			}],
			padding:2,
			border:false
		});
		me.tabPanel = Ext.create('widget.tabpanel', {
			region: 'center',
		});
		//create tab
		//profile-tab
		/*me.profileTab = Ext.create('widget.panel', {
			layout:'border',
			title: CDR.I18N['profile.tab.title'],
			border: false,
			iconCls: 'tab-profile',
			padding: 3
		});
		var serviceProvider = Ext.createWidget('serviceprovider');
		var pbxFactory = Ext.createWidget('pbxfactory');
		var userFactory = Ext.createWidget('userfactory');
		var accordion = new Ext.panel.Panel({
			layout:'accordion',
			border: false,
			defaults: {
				// applied to each contained panel
				bodyStyle: 'padding:10px'
			},
			layoutConfig: {
				// layout-specific configs go here
				titleCollapse: false,
				animate: true,
				activeOnTop: true
			},
			items: [pbxFactory, serviceProvider, userFactory]
		});
		me.profileTab.west = Ext.create('widget.panel', {
			region:'west',
			collapsible: false,
			split: true,
			width: '20%',
			layout: 'fit',
			items: [accordion]
		});
		
		me.profileTab.add(me.profileTab.west);
		//center region
		
		me.profileTab.center = Ext.create('widget.container', {
			region:'center',
			layout: 'fit',
			items:[pbxFactory.pbx]
		});
		serviceProvider.profileCenter = me.profileTab.center;
		pbxFactory.profileCenter = me.profileTab.center;
		userFactory.profileCenter = me.profileTab.center;
		me.profileTab.add(me.profileTab.center);
		
		
		me.tabPanel.add(me.profileTab);
		
		//aaa-tab
		me.siteTab = Ext.create('widget.panel', {
			layout:'border',
			title:CDR.I18N['organization.tab.title'],
			padding: 3,
			items:[Ext.create('CDR.widget.Site', {region: 'center'})]
		});
		me.tabPanel.add(me.siteTab);*/
		me.tabPanel.add(Ext.create('CDR.view.TariffCallRecord'));
		//me.tabPanel.add(Ext.create('CDR.view.recovery.TariffRecovery'));
		me.tabPanel.setActiveTab(0);
		me.root.add(me.tabPanel);
		me.add(me.root);
	}
});

Ext.onReady(function() {
	CDRUtils.amq = org.activemq.Amq;
  	CDRUtils.amq.init({ 
	    uri: 'amq', 
	    logging: true,
	    timeout: 20
  	});
	mainApp = Ext.create('CDR.Main');
});